VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmAdd 
   Caption         =   "Add a New Location"
   ClientHeight    =   10000
   ClientLeft      =   0
   ClientTop       =   -11880
   ClientWidth     =   10000
   OleObjectBlob   =   "frmAdd.frx":0000
   StartUpPosition =   1  'CenterOwner
End
Attribute VB_Name = "frmAdd"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'WRITTEN BY JALISA GREENE
'LAST MODIFIED BY JALISA GREENE
'LAST MODIFIED 6/11/2014

Option Explicit
'**EVERY VARIABLE MUST BE DECLARED**'

Private Sub UserForm_Initialize()
'**THIS SUB IS CALLED WHEN A USER OPENS THE FORM, PUTS IN HEADER INFORMATION**'

    lblLocID.Visible = True
    txtLocID.Visible = True
    txtClientName.Text = Worksheets("INV").Range("B1").Text
    txtAuditNum.Text = Worksheets("INV").Range("B2").Text
End Sub


Private Sub btnCancel_Click()
'**ACTION SUB WHEN A USER CLICKS CANCEL BUTTON**'

    frmAdd.Hide
End Sub

Private Sub btnSaveAdd_Click()
'**ACTION SUB WHEN A USER CLICKS SAVE BUTTON**'

Dim msg As Integer
    '**CHECK TO SEE IF ANY REQUIRED INFORMATION IS MISSING**'
    If txtLocID.Value = "" Then
        msg = MsgBox("You must enter a Location ID", vbOKOnly, "Missing Information")
    ElseIf txtAddr.Value = "" Then
        msg = MsgBox("You must enter a valid Address", vbOKOnly, "Missing Information")
    ElseIf txtCity.Value = "" Then
        msg = MsgBox("You must enter a valid City", vbOKOnly, "Missing Information")
   ElseIf txtState.Value = "" Then
        msg = MsgBox("You must enter a valid State", vbOKOnly, "Missing Information")
    ElseIf txtZip.Value = "" Then
        msg = MsgBox("You must enter a valid Zip", vbOKOnly, "Missing Information")
    Else:
        Call callSave
    End If
End Sub

Private Sub callSave()
'**RAN IF USER CLICKED SAVE BUTTON AND IS NOT MISSING ANY REQUIRED INFORMATION, ADDS NEW LOCATION TO THE INVENTORY TAB, ASR, SR DATA FILE, AND AFFECTED ACCTS LIST**'
    Dim lastRow As Integer
    lastRow = Worksheets("INV").Range("A500").End(xlUp).Row + 1
    
    Worksheets("INV").Range("A" & lastRow).Value = frmAdd.txtLocID.Value
    Worksheets("INV").Range("B" & lastRow).Value = frmAdd.txtDBA.Text
    Worksheets("INV").Range("C" & lastRow).Value = frmAdd.txtAddr.Text
    Worksheets("INV").Range("D" & lastRow).Value = frmAdd.txtCity.Text
    Worksheets("INV").Range("E" & lastRow).Value = frmAdd.txtState.Text
    Worksheets("INV").Range("F" & lastRow).Value = frmAdd.txtZip.Value
    Worksheets("ASR").Range("A" & lastRow).Value = Worksheets("INV").Range("A" & lastRow).Value
    Worksheets("Affected Account List ").Range("A" & (lastRow + 1)).Value = frmAdd.txtLocID.Value
    Worksheets("SR Data").Range("A" & (lastRow + 1)).Value = frmAdd.txtLocID.Value
        
    Unload frmAdd
    
    '**DISABLE EVENTS SO WHEN WE CLEAR THE LOCATIONS BOX IT DOES NOT THINK WE SELECTED ONE**'
    Application.EnableEvents = False
    frmINV.cmbLocations.Clear
    Application.EnableEvents = True
    
    '**REPOPULATE THE LOCATIONS BOX SO IT INCLUDES OUR NEW LOCATION**'
    Dim aCell As Range
    For Each aCell In Range("locations")
        If Len(aCell.Value) > 0 Then
        frmINV.cmbLocations.AddItem (aCell.Value)
        End If
    Next
End Sub

